import server from "~/axios"
/* 获取音乐url */
export const getMusicUrl = (id) => server({
    url: `/song/url?id=${id}&`,
    method: "get",
})
/* 获取音乐歌词 */
export const getLyric = (id) => server({
    url: `/lyric?id=${id}&`,
    method: "get",
})
/* 获取音乐详情 */
export const getMusicListByIds = (ids) => server({
    url: `//song/detail?ids=${ids}&`,
    method: "get",
})


/* 下载 */
export const downloadMusic = (musicUrl, fileName) => {

    getBlob(musicUrl)
        .then((res) => {
            let blob = res;
            let href = URL.createObjectURL(blob);
            console.log(href);
            let a = document.createElement("a");
            a.href = href;
            a.download = fileName
            document.body.appendChild(a);
            a.click();
            document.body.removeChild(a);
            Vue.prototype.$message.success(`${fileName}下载成功`)
        })
        .catch((err) => {
            console.log(err);
            Vue.prototype.$message.$message.error('下载失败,请稍后重试!')
        });

}